package _30_连续子数组的最大和;

//连续子序最大和
//dp[i]表示以i结尾的最大和   dp[i] = dp[i-1]>0?dp[i-1]+array[i] :array[i]
public class Solution {
    public int FindGreatestSumOfSubArray(int[] array) {
        if (array.length == 0) return 0;
        int max;
        int dp[] = new int[array.length];
        dp[0] = array[0];
        max = dp[0];
        for (int i = 1; i < array.length; i++) {
            dp[i] = dp[i-1]>0? dp[i-1]+array[i] :array[i];
            max = Math.max(max,dp[i]);
        }
        return max;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int nums[] = {6,-3,-2,7,-15,1,2,2};
        System.out.println(solution.FindGreatestSumOfSubArray(nums));
    }
}
